<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ include file="/WEB-INF/page/public/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <title>用户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${ctx }/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="${ctx }/css/font_eolqem241z66flxr.css"
          media="all" />
    <link rel="stylesheet" href="${ctx }/css/list.css" media="all" />
    <script>
        var ctx = "${ctx}";
    </script>
</head>
<body class="childrenBody">
<blockquote class="layui-elem-quote list_search">
    <shiro:hasPermission name="wx:tag:add">
        <div class="layui-inline">
            <a class="layui-btn layui-btn-normal tagBatch_btn"><i
                    class="layui-icon">&#xe608;</i> 打标签</a>
        </div>
    </shiro:hasPermission>
</blockquote>
<div class="layui-form">
    <table id="userList" lay-filter="userList"></table>
</div>
<script type="text/javascript" src="${ctx }/layui/layui.js"></script>
<script type="text/html" id="imgTpl">
    <img src="{{d.headimgurl}}"/>
</script>

<script>
    layui.config({
        base : "js/"
    }).use(
        [ 'form', 'layer', 'jquery', 'table', 'laydate' ],	function() {
            var form = layui.form,
                table = layui.table,
                layer = parent.layer === undefined ? layui.layer: parent.layer,
                laydate = layui.laydate
            $ = layui.jquery,
                nowTime = new Date().valueOf(),
                max = null,
                active = {
                    search : function() {
                        var nickname = $('#nickname'), sex = $('#sex option:selected'), status = $('#status option:selected');
                        createTimeStart = $("#createTimeStart"),
                            createTimeEnd = $("#createTimeEnd");
                        //执行重载
                        table
                            .reload(
                                'userList',
                                {
                                    page : {
                                        curr : 1
                                        //重新从第 1 页开始
                                    },
                                    where : {
                                        //key: {
                                        nickname : nickname
                                            .val(),
                                        sex : sex
                                            .val(),
                                        status : status
                                            .val(),
                                        createTimeStart : createTimeStart
                                            .val(),
                                        createTimeEnd : createTimeEnd
                                            .val()
                                        //}
                                    }
                                });
                    }
                };

            //加载页面数据
            table
                .render({
                    id : 'userList',
                    elem : '#userList',
                    url : ctx + '/wx/getWxUserList' //数据接口
                    ,
                    limit : 10//每页默认数
                    ,
                    limits : [ 10, 20, 30, 40 ],
                    cols : [ [ //表头
                        {
                            type : 'checkbox'
                        },
                        {
                            field : 'openid',
                            title : 'OPENID'
                        },
                        {
                            field : 'nickname',
                            title : '昵称'
                        },
                        {
                            field : 'headimgurl',
                            title : '头像',
                            templet : '#imgTpl'
                        },
                        {
                            field : 'remark',
                            title : '备注'
                        } ] ],
                    page : true
                    ,where: {timestamp: (new Date()).valueOf()}
                    //开启分页
                });


            //批量删除
            $(".tagBatch_btn")
                .click(
                    function() {
                        var checkStatus = table
                            .checkStatus('userList'), data = checkStatus.data, userStr = '';
                        if (data.length > 0) {
                            $.each(data, function(n,
                                                  value) {
                                userStr +='"'+ value.openid+'"'
                                    + ',';
                            });
                            userStr = userStr
                                .substring(
                                    0,
                                    userStr.length - 1);
                            layer
                                .confirm(
                                    '确定给这<strong>'
                                    + data.length
                                    + '</strong>个用户打标签吗？',
                                    function(
                                        index) {
                                        //调用删除接口
                                        $
                                            .ajax({
                                                url : ctx
                                                + '/wx/batchUsers/'
                                                + userStr+"/"+${tag.id},//接口地址
                                                type : "get",
                                                success : function(
                                                    d) {
                                                    if (d.code == 0) {
                                                        //删除成功，刷新父页面
                                                        parent.location
                                                            .reload();
                                                    } else {
                                                        layer
                                                            .msg(
                                                                "权限不足，联系超管！",
                                                                {
                                                                    icon : 5
                                                                });
                                                    }
                                                }
                                            })
                                    });
                        } else {
                            layer.msg("请选择需要打标签的用户");
                        }
                    })

        })
</script>
</body>
</html>